
<?php
//模块插件类
//对外接口函数类，其他插件可通过“$this->plugin('jy_qier')->方法名” 来调用本类的方法
defined('BY_JYA') or exit('error');
class func_jy_qier extends plugin{
	public function rtmp($title,$start_time,$end_time,$cover_pic,$rtmp_url){
        $param=$this->get_param();//获取参数
		$url = 'https://api.om.qq.com/articlev2/clientpublive?access_token='.$param['access_token'].'&title='.$title.'&start_time='.$start_time.'&end_time='.$end_time.'&cover_pic='.$cover_pic.'&rtmp_url='.$rtmp_url; //发布rtmp直播URL
		$post=array('from'=>'isjinyun');
		$post=ijson_encode($post);
		$res = cfc('http')->ihttp_request($url,$post);
		$data=json_decode($res['content'],true);
		return $data;
	}
	public function article($title,$content,$cover_pic,$category){
        $param=$this->get_param();//获取参数
		$url = 'https://api.om.qq.com/articlev2/clientpubpic?access_token='.$param['access_token'].'&title='.$title.'&cover_pic='.$cover_pic.'&category='.$category.'&content='.$content; //发布图文URL
		$post=array('from'=>'isjinyun');
		$post=ijson_encode($post);
		$res = cfc('http')->ihttp_request($url,$post);
		$data=json_decode($res['content'],true);
		if($data['code']){
			exi('推送企业号失败：'.$data['code'].$data['msg'],'error');
		}
		return $data['data'];
	}
	public function video($title,$content,$cover_pic){
        $param=$this->get_param();//获取参数
		$url = ' https://api.om.qq.com/articlev2/clientpubpic?access_token='.$param['access_token'].'&title='.$title.'&cover_pic='.$cover_pic.'&content='.$content; //发布图文URL
		$post=array('from'=>'isjinyun');
		$post=ijson_encode($post);
		$data = cfc('http')->ihttp_request($url,$post);
		return $data;
	}
	private function get_param(){
		$setting=$this->get_setting();
		$client_id=$setting['client_id'];
		$client_secret=$setting['client_secret'];
		$url='https://auth.om.qq.com/omoauth2/accesstoken?grant_type=clientcredentials&client_id='.$client_id.'&client_secret='.$client_secret;
		$post=array('from'=>'isjinyun');
		$post=ijson_encode($post);
		$param=cfc('http')->ihttp_request($url,$post);
		$param['client_id']=$client_id;
		$param['client_secret']=$client_secret;
		return $param;
	}

	

}
?>
